package io.github.xbeeant.eoffice.service.impl;

import io.github.xbeeant.core.IdWorker;
import io.github.xbeeant.eoffice.config.AbstractSecurityMybatisPageHelperServiceImpl;
import io.github.xbeeant.eoffice.mapper.AttachmentMapper;
import io.github.xbeeant.eoffice.mapper.DocTemplateMapper;
import io.github.xbeeant.eoffice.model.Attachment;
import io.github.xbeeant.eoffice.model.DocTemplate;
import io.github.xbeeant.eoffice.service.IDocTemplateService;
import io.github.xbeeant.spring.mybatis.pagehelper.IMybatisPageHelperDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 模板
 */
@Service
public class DocTemplateServiceImpl extends AbstractSecurityMybatisPageHelperServiceImpl<DocTemplate, Long> implements IDocTemplateService {

    @Autowired
    private DocTemplateMapper docTemplateMapper;

    @Autowired
    private AttachmentMapper attachmentMapper;

    @Override
    public IMybatisPageHelperDao<DocTemplate, Long> getRepositoryDao() {
        return this.docTemplateMapper;
    }

    @Override
    public void setDefaults(DocTemplate record) {
        if (record.getTid() == null) {
            record.setTid(IdWorker.getId());
        }
    }

    @Override
    public Attachment templateInfo(Long tid) {
        DocTemplate docTemplate = docTemplateMapper.selectByPrimaryKey(tid);
        return attachmentMapper.selectByPrimaryKey(docTemplate.getAid());
    }
}
